package com.zrt.dao;

import com.zrt.domain.Author;
import com.zrt.domain.Reference;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper

public interface AuthorDao {
    @Insert("insert into testparsedb.author values (#{id},#{name})")
    void insert(Author author);

    @Select("select * from testparsedb.author")
    @Results({
                @Result(id = true,column = "id",property = "id"),
                @Result(column = "name",property = "name"),
                @Result(
                        property = "citationList",
                        column = "id",
                        javaType = List.class,
                        many = @Many(select = "com.zrt.dao.CitationDao.findByAid")
                )
            })
    List<Author> selectAllAuthorAndCitation();

    @Select("select * from testparsedb.author where name like CONCAT('%', #{name}, '%')")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "name",property = "name"),
            @Result(
                    property = "citationList",
                    column = "id",
                    javaType = List.class,
                    many = @Many(select = "com.zrt.dao.CitationDao.findByAid")
            )
    })
    List<Author> selectLikeAllAuthorAndCitation(String name);

    @Select("select * from testparsedb.author where id = #{id}")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "name",property = "name"),
            @Result(
                    property = "citationList",
                    column = "id",
                    javaType = List.class,
                    many = @Many(select = "com.zrt.dao.CitationDao.findByAid")
            )
    })
    Author selectAllAuthorAndCitationById(String id);

    @Select("select * from testparsedb.author where id = #{id}")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "name",property = "name"),
            @Result(
                    property = "citationList",
                    column = "id",
                    javaType = List.class,
                    many = @Many(select = "com.zrt.dao.CitationDao.findByAid")
            )
    })
    List<Author> selectAllAuthorAndCitationListById(String id);

    @Select("select * from testparsedb.author")
    List<Author> selectAll();

    @Select("select * from testparsedb.author where name like CONCAT('%', #{name}, '%')")
    List<Author> selectAuthorLike(String name);



}

